<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>document</title>
</head>
<body>
<script type="text/javascript">
    function ArrayList() {
        this.array = []
        ArrayList.prototype.insert = function (item) {
            this.array.push(item)
        }
        ArrayList.prototype.toString = function () {
            return this.array.join('->')
        }
        ArrayList.prototype.swap = function (m,n) {
            let temp = this.array[m]
            this.array[m] = this.array[n]
            this.array[n] = temp
        }
        ArrayList.prototype.bubbleSort = function () {
            var len = this.array.length
          for (let i = len-1; i < 0; i--) {
            for (let j = 0;j<i;j++){
              if(this.array[j]>this.array[j+1]){
                this.swap(j,j+1)
              }
            }
          }

        }

    }
    let aList = new ArrayList()
    aList.insert(10)
    aList.insert(22)
    aList.insert(14)
    aList.insert(19)
    aList.insert(25)
    aList.insert(23)
    aList.insert(31)
    aList.insert(18)
    alert(aList)
    aList.bubbleSort();
    alert(aList)
</script>
</body>
</html>